name: Push to GitHub Container Registry

on:
  push:
    branches:
      - dev

permissions: write-all

jobs:
  build-and-push:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        uses: actions/checkout@v2
      - name: set lower case owner name
        run: |
          echo "OWNER_LC=${OWNER,,}" >>${GITHUB_ENV}
        env:
          OWNER: '${{ github.repository_owner }}'
      - name: set lower case repo name
        run: |
          echo "REPO_LC=${REPO,,}" >>${GITHUB_ENV}
        env:
          REPO: '${{ github.event.repository.name }}'
      - name: Login to GitHub Container Registry
        uses: docker/login-action@v1
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}

      - name: Build and push client image
        uses: docker/build-push-action@v2
        with:
          context: .
          file: Dockerfile.client
          push: true
          tags: ghcr.io/${{ env.OWNER_LC }}/${{ env.REPO_LC }}/client:${{ github.sha }}

      - name: Build and push server image
        uses: docker/build-push-action@v2
        with:
          context: .
          file: Dockerfile.server
          push: true
          tags: ghcr.io/${{ env.OWNER_LC }}/${{ env.REPO_LC }}/server:${{ github.sha }}
